package com.wangjiangfei.controller;

import com.wangjiangfei.domain.ServiceVO;
import com.wangjiangfei.entity.Freight;
import com.wangjiangfei.service.CustomerService;
import com.wangjiangfei.service.FreightService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Map;

/**
 * @author : wangjiangfei
 * @date : 2025/2/9
 * @description : 货运信息controller
 */
@RestController
@RequestMapping("/freight")
public class FreightController {

    @Autowired
    private FreightService freightService;

    /**
     * 分页查询运费
     * @param page 当前页数
     * @param rows 每页显示的记录数
     * @return
     */
    @RequestMapping("/list")
    @RequiresPermissions(value = "客户管理")// 有客户管理菜单权限的才给予调用
    public Map<String,Object> list(Integer page, Integer rows, String area) {
        return freightService.list(page, rows,area);
    }

    // 修改运费方案
    @PostMapping("/update")
    public ServiceVO<Void> updateFreight(@RequestBody Freight freight) {
        freightService.updateFreight(freight);
        return ServiceVO.success();
    }

    // 删除运费方案
    @PostMapping("/delete")
    public ServiceVO<Void> deleteFreight(@RequestParam Integer freightId) {
        freightService.deleteFreight(freightId);
        return ServiceVO.success();
    }

    // 新增运费方案
    @PostMapping("/add")
    public ServiceVO<Void> addFreight(@RequestBody Freight freight) {
        freightService.addFreight(freight);
        return ServiceVO.success();
    }
}
